package com.smalls.newvideotwo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.smalls.newvideotwo.R;
import com.smalls.newvideotwo.db.Album;
import com.smalls.newvideotwo.utils.ImageLoaderUtil;
import com.smalls.newvideotwo.utils.MeasureUtil;
import com.smalls.newvideotwo.utils.Tools;

import java.util.ArrayList;
import java.util.List;

public class SearchTypeAdapter extends BaseAdapter {
    private Context context;
    private ImageLoaderUtil imageLoaderUtil = new ImageLoaderUtil();
    public List<Album> vodDatas;

    static class ViewHolder {
        private ImageView poster;
        private TextView videoName;

        ViewHolder() {
        }
    }

    public SearchTypeAdapter(Context context, List<Album> datas) {
        this.context = context;
        this.vodDatas = datas;
    }

    public void changData(List<Album> paramArrayList) {
        setVideos(paramArrayList);
        notifyDataSetChanged();
    }

    private void setVideos(List<Album> paramArrayList) {
        if (paramArrayList != null) {
            this.vodDatas = paramArrayList;
        } else {
            this.vodDatas = new ArrayList();
        }
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(this.context).inflate(R.layout.movetype_details_item, null);
            holder = new ViewHolder();
            holder.poster = (ImageView) convertView.findViewById(R.id.video_poster);
            holder.videoName = (TextView) convertView.findViewById(R.id.video_name);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Album searchItem = (Album) this.vodDatas.get(position);
        this.imageLoaderUtil.loadImage(searchItem.getAlbumPic(), holder.poster, this.context, R.mipmap.default_poster, 0);
        holder.videoName.setText(searchItem.getTitle());

        return convertView;
    }

    public int getCount() {
        return this.vodDatas.size();
    }

    public Object getItem(int position) {
        return this.vodDatas.get(position);
    }

    public long getItemId(int position) {
        return (long) position;
    }
}
